home *** CD-ROM | disk | FTP | other *** search
-
-
-
- MALLOC(3) MINTLIB LIBRARY FUNCTIONS MALLOC(3)
-
-
- N✓NA✓AM✓ME✓E
- malloc, free, realloc, calloc, alloca - memory allocator
-
- S✓SY✓YN✓NO✓OP✓PS✓SI✓IS✓S
- #include <stdlib.h>
-
- void *malloc(size_t size);
-
- void free(void *ptr);
-
- void *realloc(void *ptr, size_t size);
-
- void *calloc(size_t num_elems, size_t elem_size);
-
- void *alloca(size_t size);
-
- D✓DE✓ES✓SC✓CR✓RI✓IP✓PT✓TI✓IO✓ON✓N
- These routines provide a general-purpose memory allocation
- package. They maintain a table of free blocks for effi-
- cient allocation and coalescing of free storage. When
- there is no suitable space already free, the allocation
- routines call Malloc to get more memory from the system.
-
- Each of the allocation routines returns a pointer to space
- suitably aligned for storage of any type of object. Each
- returns a NULL pointer if the request cannot be completed
- or if an area of size zero is requested.
-
- malloc returns a pointer to a block of at least size
- bytes.
-
- free releases a previously allocated block. Its argument
- is a pointer to a block previously allocated by malloc,
- calloc or realloc.
-
- realloc changes the size of a block referenced to by ptr
- to size bytes and returns a pointer to the (possibly
- moved) block. The contents will be unchanged up to the
- lesser of the new and old sizes. If unable to honor a
- reallocation request, realloc leaves it first argument
- unaltered. Using realloc with a block freed before is an
- error.
-
- realloc(NULL, size) is the same as malloc(size). real-
- loc(ptr, 0) is the same as free(ptr).
-
- calloc uses malloc to allocate space for an array of
- num_elems elements of size elem_size, initialises the
- space to zeros, and returns a pointer to the initialised
- block.
-
- alloca allocates size bytes of space in the stack frame of
- the caller, and returns a pointer to the allocated block.
- This temporary space is automatically freed when the
-
-
-
- MiNT docs 0.1 3 March 1993 1
-
-
-
-
-
- MALLOC(3) MINTLIB LIBRARY FUNCTIONS MALLOC(3)
-
-
- caller returns. Note that if the allocated block is beyond
- the current stack limit, the resulting behavior is unde-
- fined.
-
- R✓RE✓ET✓TU✓UR✓RN✓N V✓VA✓AL✓LU✓UE✓ES✓S
- On success, malloc, calloc, realloc and alloca return a
- pointer to space suitably aligned for storage of any type
- of object. On failure, they return NULL.
-
- S✓SE✓EE✓E A✓AL✓LS✓SO✓O
- M✓Ma✓al✓ll✓lo✓oc✓c(✓(2✓2)✓),✓, g✓ge✓et✓tr✓rl✓li✓im✓mi✓it✓t(✓(3✓3)✓)
-
- W✓WA✓AR✓RN✓NI✓IN✓NG✓GS✓S
- On UN*X machines, malloc and realloc return a non-NULL
- pointer if size is 0, and calloc returns a non-NULL
- pointer if num_elems or elem_size is 0. The mintlibs fol-
- low the ANSI-C standard and return NULL in these circum-
- stances.
-
- alloca is machine-, compiler-, and most of all, system-
- dependent. Its use is strongly discouraged.
-
- N✓NO✓OT✓TE✓ES✓S
- GNU software is uncommonly fond of alloca.
-
- To use alloca with Pure-C in the current version of the
- mintlibs, the caller must be compiled with the -S option
- set or the program will crash.
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- MiNT docs 0.1 3 March 1993 2
-
-
-